'''
This script get the result of manual segmentation and self segmentation
'''

import pandas as pd

file = pd.read_csv('../image_annotation.csv')

def get_short_path(p):
	p = p.split('/')[-1]
	p = p.split('.')[0]
	p = p.split('_')
	return '_'.join([p[0],p[1],p[-1]])+'.JPG'


gradeRes = {}

for i in range(file.shape[0]):
	record = file.iloc[i]
	if record['path'].startswith('grade'):
		continue
	path = get_short_path(record['path'])
	level = record['level']
	if path in gradeRes and gradeRes[path] != 100:
		continue
	gradeRes[path] = level


file_content = open('result.txt','r').read().splitlines()
err = 0
acc = 0
loss = 0
quality = 0
for l in file_content:
	path, level = l.split(',')
	level = int(level)
	# print(path,level)
	if not path in gradeRes:
		loss += 1
		continue
	if gradeRes[path] == 100:
		quality += 1
		continue
	if (gradeRes[path]) == (level):
		acc += 1
	else:
		err += 1
		print(path,level, gradeRes[path])
print(quality,loss, err,acc,err+acc,acc/(err+acc))